﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebEntities;
using com.subb.WebInfo;
using WebEntities.Models.WebInfo;

namespace WebUI.Controllers
{
    public class ContactUsController : Controller
    {
        public ContactUsController()
            : base()
        {
            ViewBag.ActMenu = "contactus";
        }

        public ActionResult Index()
        {
            int id = Extensions.CommonFn.GetContentID("ContactUsId");
            WI_NewsDAL ndal = new WI_NewsDAL();
            WI_News news1 = ndal.GetNews(id, false);
            return View(news1);
        }

        public ActionResult LeaveMessage()
        {
            return View();
        }

        [HttpPost]
        public ActionResult LeaveMessage(string username, string email, string mobile, string msg)
        {
            string resultMsg = string.Empty;
            if (string.IsNullOrWhiteSpace(username))
            {
                resultMsg = "请填写您的名称";
            }
            else if (msg.Trim().Length < 8)
            {
                resultMsg = "请不要吝言，以帮助我们提高服务质量，谢谢。";
            }
            else
            {
                WI_LeaveMsgDAL ldal = new WI_LeaveMsgDAL();
                LeaveMsg lmsg = new LeaveMsg
                {
                    ContactMan = username,
                    Email = email,
                    Mobile = mobile,
                    MsgBody = msg
                };
                ldal.CreateLeaveMsg(lmsg);
                resultMsg = "created";
            }
            ViewBag.Msg = resultMsg;
            return View();
        }
    }
}
